package com.jiaju.servlet;

import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jiaju.utils.DBManager;
import com.jiaju.utils.class1;


@WebServlet("/headerServlet")
public class headerServlet extends HttpServlet {
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		List<class1> A =new ArrayList<class1>();
		try {
			Connection conn =DBManager.getConn();
			Statement st = conn.createStatement();
			String sql ="select id,title,imgUrl,toUrl from banner";
			ResultSet rs = st.executeQuery(sql);
			while(rs.next()) {
				int id = rs.getInt("id");
				String title = rs.getString("title");
				String imgUrl =rs.getString("imgUrl");
				String toUrl =rs.getString("toUrl");
				class1 z =new class1(id,title,imgUrl,toUrl);
				A.add(z);
			}
			rs.close();
			st.close();
			conn.close();
		} catch (SQLException e)  {
			e.printStackTrace();
		}
		req.setAttribute("A", A);
		req.getRequestDispatcher("header.jsp").forward(req, res);
		
	}
	}


	
//		
